<script setup>
import { onUnmounted, ref } from "vue";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
dayjs.locale("zh-cn");

const time = ref();
let timeKey = null;
const week = ref();
const year = ref();
const isStop = ref(false);

function refreshTime() {
  timeKey && clearTimeout(timeKey);
  if (isStop.value) return;
  const now = dayjs();
  time.value = now.format("HH:mm:ss");
  week.value = now.format("dddd");
  year.value = now.format("YYYY/MM/DD");
  timeKey = window.setTimeout(refreshTime, 1000);
}

refreshTime();

onUnmounted(() => {
  isStop.value = true;
});

defineProps({
  msg: String,
});
</script>

<template>
  <div class="header-panel">
    <div class="time-panel">
      <div class="time-text">{{ time }}</div>
      <div class="month-panel">
        <div class="week-text">{{ week }}</div>
        <div class="month-text">{{ year }}</div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.header-panel {
  width: 100%;
  height: 136px;
  background: url("/src/assets/header.png") no-repeat;
  background-size: 100% 100%;
  position: relative;
  .time-panel {
    position: absolute;
    right: 24px;
    top: 60px;
    width: 279px;
    height: 50px;
    background: url("/src/assets/saler-bg.png") no-repeat;
    background-size: 100% 100%;
    color: #e6fffe;
    display: flex;
    align-items: center;
    .time-text {
      font-size: 24px;
      font-weight: bold;
      color: #e6fffe;
      line-height: 30px;
      letter-spacing: 2px;
      padding-right: 30px;
      border-right: 1px solid rgba(230, 255, 254,0.7);
      margin-right: 30px;
    }
    .week-text,
    .month-text {
      font-size: 12px;
      font-weight: 400;
      color: #e6fffe;
      line-height: 16px;
      letter-spacing: 1px;
    }
  }
}
</style>
